var express = require('express');
var router = express.Router();
let createDBconnect = require("../db/createDBconnect.js");

router.post("/registered",async (req,res) => {
    try{
        let connect = createDBconnect();
        let userInfo = Object.assign(req.body);
        console.log(userInfo);
        let sqlString = `insert into users(userid,password,username,phoneNumber,email) values('${userInfo.userid}','${userInfo.password}','${userInfo.username}','${userInfo.phoneNumber}','${userInfo.email}')`
        // let sqlString =  

        connect.query(sqlString,(err,result) => {
            if (err) {
                console.log(`SQL error: ${err}!`);
                res.status(400).send({status: 400})
              } else {
                // console.log(result);
                res.status(200).send({message: "注册成功",status: 200});
              }
        })
     

    }catch(err){
        res.status(400).send(err);
        connect.off();
    }
})

module.exports = router;